package com.xzuf.core.ui;

import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xzuf.core.vo.xml.DataSourceVO;
import com.xzuf.pub.DateUtils;
import com.xzuf.pub.FileUtils;
import com.xzuf.pub.GlobalValue;
import com.xzuf.pub.GuiUtils;

/**
 * 程序入口
 * @author xzgf
 * @since 2008-7-11
 * @version 1.0
 */
public class StartUI {

	private static final Log logger = LogFactory.getLog(StartUI.class);
	/**
	 * @author xzgf 2008-7-11
	 * @param args
	 */
	public static void main(String[] args) {
		logger.info("***************************************************");
		logger.info("     ExpandablePlatform V1.0          ");
		logger.info("        2008-07-11            ");
		logger.info("     gaofeng@foxmail.com\t\t  ");
        logger.info("***************************************************");
        logger.info(DateUtils.getSingleton().getCurTime());
        logger.info("System starting...");
        
        //初始化数据库属性
		try {
			GlobalValue.sysProp = FileUtils.getSystemPropertyFromXML(GlobalValue.CONFIG_FILE_BAT);
			logger.info("set default datasource..");
			List<DataSourceVO> list = GlobalValue.sysProp.getContent();
			Iterator<DataSourceVO> iter = list.iterator();
			while(iter.hasNext()) {
				DataSourceVO vo = iter.next();
				if(vo.isDefault()) {
					GlobalValue.DefaultDataSource = vo;
					logger.info("set default datasource success...");
					break;
				}
				logger.info("No default datasource,pls set it...");
			}
			
		} catch (FileNotFoundException e) {
			GuiUtils.showMessage(e.getMessage(), GlobalValue.mainFrame);
		}
        
		MainUI mainFrame = new MainUI();
		mainFrame.setLocationRelativeTo(null);
		mainFrame.setVisible(true);

	}

}
